package com.five.system.controller;

import com.five.basic.result.PageList;
import com.five.pojo.Permission;
import com.five.result.Result;
import com.five.system.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @PostMapping("/queryPage")
    public Result queryPage(@RequestBody Permission permission) {
        try {
            PageList<Permission> permissionPageList = permissionService.queryPage(permission);
            return Result.success(permissionPageList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    @PostMapping("/queryAll")
    public Result queryAll() {
        try {
            return Result.success(permissionService.queryAll());
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }


    @PostMapping("queryByUserId/{userId}")
    public Result<List<String>> queryPermissionsByUserId(@PathVariable Long userId){
        try {
            List<String> permissions = permissionService.queryByUserId(userId);
            return Result.success(permissions);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("服务器异常");
        }
    }

}
